package com.myorg.search;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.myorg.service.StartupService;
import com.myorg.util.ConstantsToBeExternalized;
import com.myorg.util.EmailTransformAndLoader;

@ManagedBean
@ViewScoped
public class UploadBean extends BaseBean implements Serializable {
	private static final long serialVersionUID = 6423736708982985245L;
	final static private Logger logger = LoggerFactory.getLogger(UploadBean.class);

	private boolean compress;

	public void handleFileUpload(FileUploadEvent event) {
		StartupService.touch();
		UploadedFile file = event.getFile();
		logger.info("File <" + file.getFileName() + "> has been uploaded.");
		EmailTransformAndLoader.transformAndLoad(file, compress);
	}

	public boolean isCompress() {
		return compress;
	}

	public void setCompress(boolean compress) {
		this.compress = compress;
	}

	public String getMaxSizeOfFileUpload() {
		return String.valueOf(ConstantsToBeExternalized.MAX_SIZE_OF_FILES_UPLOAD);
	}

	public String getMaxNumOfFileUpload() {
		return String.valueOf(ConstantsToBeExternalized.MAX_NUM_OF_FILES_UPLOAD);
	}
}
